package org.changs.game.android.data.db.model;


import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.List;

@Entity(nameInDb = "book")
public class Book {
    /**
     * ISBN号
     */
    @Expose
    @SerializedName("isbn")
    @Property(nameInDb = "isbn")
    @Index(name = "isbn", unique = true)
    @Id
    private String isbn;
    /**
     * 书页特征码文件地址
     */
    @Expose
    @SerializedName("page_file_url")
    @Property(nameInDb = "page_file_url")
    private String pageFileUrl;
    /**
     * 书页特征码文件MD5值
     */
    @Expose
    @SerializedName("page_file_md5")
    @Property(nameInDb = "page_file_md5")
    private String pageFileMD5;
    /**
     * 书页列表
     */
    @ToMany(referencedJoinProperty = "bookId")
    private List<BookPage> bookPages;
    /**
     * Used to resolve relations
     */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /**
     * Used for active entity operations.
     */
    @Generated(hash = 1097957864)
    private transient BookDao myDao;

    @Generated(hash = 1447585877)
    public Book(String isbn, String pageFileUrl, String pageFileMD5) {
        this.isbn = isbn;
        this.pageFileUrl = pageFileUrl;
        this.pageFileMD5 = pageFileMD5;
    }

    @Generated(hash = 1839243756)
    public Book() {
    }

    public String getIsbn() {
        return this.isbn;
    }

    public void setIsbn(String isbn) {
        this.isbn = isbn;
    }

    public String getPageFileUrl() {
        return this.pageFileUrl;
    }

    public void setPageFileUrl(String pageFileUrl) {
        this.pageFileUrl = pageFileUrl;
    }

    public String getPageFileMD5() {
        return this.pageFileMD5;
    }

    public void setPageFileMD5(String pageFileMD5) {
        this.pageFileMD5 = pageFileMD5;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 751851833)
    public List<BookPage> getBookPages() {
        if (bookPages == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            BookPageDao targetDao = daoSession.getBookPageDao();
            List<BookPage> bookPagesNew = targetDao._queryBook_BookPages(isbn);
            synchronized (this) {
                if (bookPages == null) {
                    bookPages = bookPagesNew;
                }
            }
        }
        return bookPages;
    }

    /**
     * Resets a to-many relationship, making the next get call to query for a fresh result.
     */
    @Generated(hash = 1149442848)
    public synchronized void resetBookPages() {
        bookPages = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1115456930)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getBookDao() : null;
    }
}
